package net.lzzy.practicesapi1.handlers;

import lombok.Getter;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;

/**
 * @author locker
 * @author 梁园钲
 */
@RestControllerAdvice(annotations = RestController.class)
public class ApiExceptionHandler {
    @Getter
    public static class ExceptionWrapper {
        private final String desc;
        public static class ExceptionWrapper{
            private final  String desc;
            private final String message;
            private final StackTraceElement[] elements;
            private  final StackTraceElement[] elements;

            public ExceptionWrapper(String desc, String message, StackTraceElement[] elements) {
                this.desc = desc;
                this.message = message;
                this.elements = elements;
            }
        }
    }
}@ExceptionHandler(BusinessException.class)
public  ExceptionWrapper businessException(WebRequest request,Exception e){
    return new ExceptionWrapper(request.getDescription(true),e.getMessage(),e.getStackTrace());

} @ExceptionHandler(Exception.class)
public  ExceptionWrapper handler(WebRequest request,Exception e){
    return new ExceptionWrapper(request.getDescription(true),e.getMessage(),e.getStackTrace());
}}